package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.etc.entity.Goodstype;
import com.etc.service.GoodsTypeService;
import com.etc.tools.AjaxOperateResponse;
import com.etc.tools.ResponseData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("api")
@Api(value = "商品类型的接口", description = "处理类型操作的后端接口")
public class GoodsTypeController {

	@Autowired
	private GoodsTypeService typeService;

	@GetMapping("goodstype")
	@ApiOperation(value = "查询类型", httpMethod = "GET", notes = "分页加模糊查询的方法", response = ResponseData.class)
	public ResponseData<Goodstype> listGoodsType(
			@ApiParam(name = "keywords", required = true, defaultValue = "", value = "查询关键字") @RequestParam(name = "keywords", required = true, defaultValue = "") String keywords,
			@ApiParam(name = "page", required = true, defaultValue = "1", value = "页码") @RequestParam(name = "page", required = true, defaultValue = "1") Integer page,
			@ApiParam(name = "limit", required = true, defaultValue = "10", value = "每页记录数") @RequestParam(name = "limit", required = true, defaultValue = "10") Integer limit) {

		ResponseData<Goodstype> rd = typeService.getGoodsTypeByLike(keywords, page, limit);
		return rd;
	}

	@PostMapping("goodstype")
	@ApiOperation(value = "增加商品类型", httpMethod = "POST", notes = "增加商品类型", response = AjaxOperateResponse.class)
	public AjaxOperateResponse addGoodsType(@RequestBody Goodstype goodstype) {
		return typeService.addGoodsType(goodstype);
	}

	@PutMapping("goodstype")
	@ApiOperation(value = "修改类型", httpMethod = "PUT", notes = "修改商品类型", response = AjaxOperateResponse.class)
	public AjaxOperateResponse updateGoodsType(@RequestBody Goodstype goodstype) {
		return typeService.updateGoodsType(goodstype);
	}

	@DeleteMapping("goodstype/{typeid}")
	@ApiOperation(value = "删除商品类型", httpMethod = "DELETE", notes = "删除商品类型", response = AjaxOperateResponse.class)
	public AjaxOperateResponse delGoodsType(
			@ApiParam(name = "typeid", required = true, value = "删除的id") @PathVariable("typeid") Integer typeid) {
		return typeService.delGoodsType(typeid);
	}

	@GetMapping("goodstype/{typeid}")
	@ApiOperation(value = "根据id查询", httpMethod = "GET", notes = "查询商品类型", response = Goodstype.class)
	public Goodstype getGoodsTypeById(
			@ApiParam(name = "typeid", required = true, value = "根据id查询，返回对象信息") @PathVariable("typeid") Integer typeid) {

		return typeService.getGoodsTypeById(typeid);

	}
}
